* Create data for Matlab: Test of the model, waves 3-5 
* 3 Jun 2020

clear all
set more off

use "$input/PovertyTraps_structural.dta" , clear

* Restrict to stups in structural estimation
rename hhid5 hhid3
cap drop _merge
merge m:1 hhid3 using "$intermediate/data_for_matlab_stups.dta"
keep if _merge==3
drop _merge

* Keep relevant variables
keep hhid3 branchid survey_wave livestock_H wage_H pAssets* wageMA cows_no hiredInLabour
replace pAssets=pAssets*1000
replace pAssets0=pAssets0*1000
gen total_H = wage_H + livestock_H
order wage_H total_H, after(livestock_H)
order hhid3, first
replace livestock_H=0 if cows_no==0
drop cows_no

* Drop irrelevant variables
keep hhid3 survey livestock_H wage_H hiredInLabour wageMA pAssets

* Export data for each survey wave 3-5
forvalues sw = 3/5 {
	preserve
	keep if survey==`sw'
	drop survey
	export delimited using "$intermediate/w`sw'_capital_of_stups.csv", novarnames replace
	save "$intermediate/w`sw'_capital_of_stups.dta", replace
	restore	
}